import java.io.*;
//import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import db.DatabaseConnector;

public class ListResourceDescriptionValues extends HttpServlet {

//This subroutine is called by ListCat.jsp
public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

	//The JSP document passes in which db table to use
	String tName = request.getParameter("tName");

	//Variables for the database connection
	DatabaseConnector con = new DatabaseConnector(DatabaseConnector.getDatabaseType());

	response.setContentType("text/html");
    	PrintWriter out = response.getWriter();

    try {
        //TODO: Query
        String SQL = "SELECT ID, CategoryName, Purpose, Active FROM " + tName;
        String[][] rs = con.selectSQL(SQL,4);
    
        out.println("<tr><td bgcolor=\"cccccc\"><b>Category Name</b></td>");
	out.println("<td bgcolor=\"cccccc\"><b>Description</b></td>");
	out.println("<td bgcolor=\"cccccc\"><b>Status</b></td>");
	out.println("<td bgcolor=\"cccccc\"><b>Edit/Remove?</b></td></tr>");

        for (int i=0;i<rs.length;i++){
            if(rs[i][2].length() > 45) {
		rs[i][2] = rs[i][2].substring(0, 45) + "...";
            }

            out.print("<tr><td>" + rs[i][1]);
            out.print("</td><td> " + rs[i][2]);
            if(rs[i][3].equals("1")) {
    		out.print("</td><td><span style=\"font-weight: bold; color:009900;\">Active</span>");
                
            } else {
    		out.print("</td><td><span style=\"font-weight: bold; color:ff0000;\">Inactive</span>");
            }
            out.print("</td><td><a href=\"EditCat.jsp?ID=" + rs[i][0] + "\">");
            out.println("Edit/Remove Category</a></td></tr>");
        }
    }
    finally
    {
        con.CleanUp();
    }
}
}
